package LimitedTimeGame.Day_0326;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author zxc
 * @date 2023/03/26 17:06
 **/
public class Ksort {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for(int i = 0 ; i < n ; i++) {
            int len = scanner.nextInt();
            int k = scanner.nextInt();
            int[] arr = new int[len];
            for(int j = 0 ; j < len ; j++){
                arr[j] = scanner.nextInt();
            }
            System.out.println(GetSort(k, arr));
        }
    }
    public static int GetSort(int k , int[] arr){
        int len = arr.length;
        int num = len;
        // 获取辅助数组temp，同时对于该辅助数组temp进行从小到大的排序;
        int[] temp = arr.clone();
        Arrays.sort(temp);
        for(int i = 0 ; i < len ; i++){
//            System.out.println(temp[i] + " " + arr[i]);
            if(temp[i] != arr[i]){
                break;
            }
            num--;
        }
        int result = num / k;
        if(num > 0 && k > num){
            result = 1;
            num = 0;
        }
        result += num % k != 0 ? 1 : 0;
        return result;
    }
}
